import numpy as np
import cv2
from mss import mss
from PIL import Image
from pynput import keyboard,mouse 
import time
while True:
    break
    time.sleep(1)
    p = mouse.Controller().position
    print(p)

bounding_box = {'top': 222, 'left': 2, 'width': 1022, 'height': 424}
sct = mss()
def wait_for_mv():
    st = time.time()
    box = {'top': 222+300, 'left': 2+300, 'width': 102, 'height': 42}
    sct_img = sct.grab(box)
    lst = np.array(sct_img)
    while True:
        if time.time()-st>3:
            return False
        time.sleep(0.1)
        sct_img = sct.grab(box)
        ll = np.array(sct_img)
        if not np.array_equal(lst,ll) :
            return True
co =0
def one(x,y):
    global co
    mouse.Controller().position = (x,y)
    time.sleep(0.1)
    mouse.Controller().click(mouse.Button.left)
    time.sleep(0.2)
    wait_for_mv()
    sct_img = sct.grab(bounding_box)
    cv2.imwrite('img/'+str(co)+'.jpg', np.array(sct_img))
    co += 1


time.sleep(5)
st = 120
end = 907
to = 12*5
gg = (end-st)/(to-1)
while co<to:
    one(st+int(co*gg),661)
